import Main from '../views/Main.vue';
import commonroutes from '@/common/router';

// 不作为Main组件的子页面展示的页面单独写，如下
export const loginroute = {
    path: '/login',
    name: 'login',
    meta: {
        title: 'Login - 登录'
    },
    component: resolve => { require(['../views/login.vue'], resolve); }
};

// 作为Main组件的子页面展示但是不在左侧菜单显示的路由写在otherroute里
export const otherroute = {
    path: '/',
    name: 'otherroute',
    component: Main,
    children: [
        { path: 'home', title: '首页', name: 'home_index', component: resolve => { require(['../views/home/home.vue'], resolve); } }
    ]
};

// 所有路由页面
export const route_list = {
    admin_role: {
        path: 'admin_role',
        icon: 'ios-paper-outline',
        name: 'admin_role',
        title: '管理员角色',
        permission: 1101,
        operations: ["11", "12", "13"],
        component: resolve => { require(['../views/role/Role.vue'], resolve); }
    },
    admin_user_add: {
        path: 'user_add',
        icon:'person-add',
        name:'admin_user_add',
        title: '添加管理员',
        permission: 1103,
        operations: ["11", "12", "13"],
        component: resolve => { require(['../views/role/adminuser.vue'], resolve); }
    },
    member_manage: {
        path: 'member_manage',
        icon:'person-add',
        name:'member_manage',
        title: "会员管理",
        permission: 1104,
        operations: ["24", "25", "12"],
        component: resolve => { require(['../views/role/member_manage.vue'], resolve); }
    },
    update_password: {
        path: 'update_password',
        icon:'gear-b',
        name:'update_password',
        title: '重置密码',
        permission: 1105,
        component: resolve => { require(['../views/role/updatePwd.vue'], resolve); }
    },
    page_manage: {
        path: 'page_manage',
        icon:'gear-b',
        name:'page_manage',
        title: '模块设置',
        permission: 1106,
        operations: ["13"],
        component: resolve => { require(['../views/role/page_manage.vue'], resolve); }
    },
    info_list: {
        path: 'info_list',
        icon: 'ios-paper-outline',
        name: 'info_list',
        title: '文章管理',
        permission: 1107,
        operations: ["11", "12", "13","19","29"],
        component: resolve => { require(['../views/info_manage/info_list.vue'], resolve); }
    },
    help_list: {
        path: 'help_list',
        icon: 'ios-paper-outline',
        name: 'help_list',
        title: '帮助中心',
        permission: 1108,
        operations:["11", "12", "13","19"],
        component: resolve => { require(['../views/info_manage/help_list.vue'], resolve); }
    },
    module_article_list: {
        path: 'module_article_list',
        icon: 'ios-paper-outline',
        name: 'module_article_list',
        title: '专项资讯管理',
        permission: 1108,
        operations:["11", "12", "13","19"],
        component: resolve => { require(['../views/info_manage/module_article_list.vue'], resolve); }
    },
    system_introduction: {
        path: 'system_introduction',
        icon: 'ios-paper-outline',
        name: 'system_introduction',
        title: '系统介绍',
        permission: 1120,
        operations:["26"],
        component: resolve => { require(['../views/dictionary/system_introduction.vue'], resolve); }
    },
    open_check: {
        path: 'open_check',
        icon: 'toggle-filled',
        name: 'open_check',
        title: '审核开关',
        permission: 1128,
        operations: ["27"],
        component: resolve => { require(['../views/check/open_check.vue'], resolve); }
    },
    firm_check: {
        path: 'firm_check',
        icon: 'android-checkbox-outline',
        name: 'firm_check',
        title: '服务机构注册信息审核',
        permission: 1132,
        operations: ["15"],
        component: resolve => { require(['../views/check/firm_check.vue'], resolve); }
    },//
    service_register_check: {
        path: 'service_register_check',
        icon: 'android-checkbox-outline',
        name: 'service_register_check',
        title: '企业注册信息审核',
        permission: 1109,
        operations: ["15"],
        component: resolve => { require(['../views/check/service_register_check.vue'], resolve); }
    },
    service_check: {
        path: 'service_check',
        icon: 'android-checkbox-outline',
        name: 'service_check',
        title: '服务信息审核',
        permission: 1110,
        operations: ["15"],
        component: resolve => { require(['../views/check/service_check.vue'], resolve); }
    },
    demand_check: {
        path: 'demand_check',
        icon: 'android-checkbox-outline',
        name: 'demand_check',
        title: '需求信息审核',
        permission: 1111,
        operations: ["15"],
        component: resolve => { require(['../views/check/demand_check.vue'], resolve); }
    },
    demand_history: {
        path: 'demand_history',
        icon: 'android-checkbox-outline',
        name: 'demand_history',
        title: '已审核需求信息',
        permission: 1111,
        operations: ["15"],
        component: resolve => { require(['../views/check/demand_history.vue'], resolve); }
    },
    service_history: {
        path: 'service_history',
        icon: 'android-checkbox-outline',
        name: 'service_history',
        title: '已审核服务信息',
        permission: 1111,
        operations: ["15"],
        component: resolve => { require(['../views/check/service_history.vue'], resolve); }
    },
    abutment_history: {
        path: 'abutment_history',
        icon: 'android-checkbox-outline',
        name: 'abutment_history',
        title: '已审核对接信息',
        permission: 1111,
        operations: ["15"],
        component: resolve => { require(['../views/check/abutment_history.vue'], resolve); }
    },
    maintain: {
        path: 'maintain',
        icon: 'ios-paper-outline',
        name: 'maintain',
        title: '系统开关',
        permission: 1112,
        operations:["31"],
        component: resolve => { require(['../views/dictionary/maintain.vue'], resolve); }
    },
    dictionary_manage: {
        path: 'dictionary_manage',
        icon: 'ios-paper-outline',
        name: 'dictionary_manage',
        title: '字典',
        permission: 1113,
        operations: ["11"],
        component: resolve => { require(['../views/dictionary/Dictionary.vue'], resolve); }
    },
    system_value: {
        path: 'system_value',
        icon: 'ios-paper-outline',
        name: 'system_value',
        title: '系统信息设置',
        permission: 1114,
        operations:["13"],
        component: resolve => { require(['../views/dictionary/free_value.vue'], resolve); }
    },
    email_value: {
        path: 'email_value',
        icon: 'ios-paper-outline',
        name: 'email_value',
        title: '邮箱接口设置',
        permission: 1115,
        operations:["11","12","13","32"],
        component: resolve => { require(['../views/dictionary/email_value.vue'], resolve); }
    },
    message_value: {
        path: 'message_value',
        icon: 'ios-paper-outline',
        name: 'message_value',
        title: '短信接口设置',
        permission: 1116,
        operations:["34"],
        component: resolve => { require(['../views/dictionary/message_value.vue'], resolve); }
    },
    GSXT_value: {
        path: 'GSXT_value',
        icon: 'ios-paper-outline',
        name: 'GSXT_value',
        title: '企业查询接口设置',
        permission: 1116,
        operations:["34"],
        component: resolve => { require(['../views/dictionary/GSXT_value.vue'], resolve); }
    },
    email_template: {
        path: 'email_template',
        icon: 'ios-paper-outline',
        name: 'email_template',
        title: '邮件模板',
        permission: 1117,
        operations:["13","12","33"],
        component: resolve => { require(['../views/dictionary/email_template.vue'], resolve); }
    },
    message_template: {
        path: 'message_template',
        icon: 'ios-paper-outline',
        name: 'message_template',
        title: '短信模板',
        permission: 1118,
        operations:["33","13","12"],
        component: resolve => { require(['../views/dictionary/message_template.vue'], resolve); }
    },
    index_logo: {
        path: 'index_logo',
        icon: 'ios-paper-outline',
        name: 'index_logo',
        title: '网站图片',
        permission: 1119,
        operations: ["11","13","14"],
        component: resolve => { require(['../views/dictionary/IndexLogo.vue'], resolve); }
    },
    admin_log: {
        path: 'admin_log',
        icon: 'ios-paper-outline',
        name: 'admin_log',
        title: '管理员日志',
        permission: 1121,
        operations:["12"],
        component: resolve => { require(['../views/log/admin_log.vue'], resolve); }
    },
    user_log: {
        path: 'user_log',
        icon: 'ios-paper-outline',
        name: 'user_log',
        title: '普通用户日志',
        permission: 1122,
        operations:["12"],
        component: resolve => { require(['../views/log/user_log.vue'], resolve); }
    },
    feedback_manage: {
        path: 'feedback_manage',
        icon: 'ios-paper-outline',
        name: 'feedback_manage',
        title: '问题反馈',
        permission: 1123,
        operations:["14","12","30"],
        component: resolve => { require(['../views/log/feedback.vue'], resolve); }
    },
    message_manage: {
        path: 'message_manage',
        icon: 'ios-paper-outline',
        name: 'message_manage',
        title: '消息管理',
        permission: 1123,
        operations:["14","12","30"],
        component: resolve => { require(['../views/log/message.vue'], resolve); }
    },
    backup_database: {
        path: 'backup_database',
        icon: 'archive',
        name: 'backup_database',
        title: '备份数据库',
        permission: 1124,
        operations: ["21"],
        component: resolve => { require(['../views/dataManager/backup_database.vue'], resolve); }
    },
    restore_database: {
        path: 'restore_database',
        icon: 'android-exit',
        name: 'restore_database',
        title: '还原数据库',
        permission: 1125,
        operations: ["22"],
        component: resolve => { require(['../views/dataManager/restore_database.vue'], resolve); }
    },
    delete_database: {
        path: 'delete_database',
        icon: 'close',
        name: 'delete_database',
        title: '删除备份数据库',
        permission: 1126,
        operations: ["12"],
        component: resolve => { require(['../views/dataManager/delete_database.vue'], resolve); }
    },
    download_database: {
        path: 'download_database',
        icon: 'arrow-down-a',
        name: 'download_database',
        title: '下载备份数据库',
        permission: 1127,
        operations: ["23"],
        component: resolve => { require(['../views/dataManager/download_database.vue'], resolve); }
    },
    release_plateformservice: {
        path: 'release_plateformservice',
        icon: 'ios-paper-outline',
        name: 'release_plateformservice',
        title: '发布平台服务',
        permission: 1129,
        operations: ["11", "13", "19", "12"],
        component: resolve => { require(['../views/plateformservice/release_plateformservice.vue'], resolve); }
    },
    plateformservice_check: {
        path: 'plateformservice_check',
        icon: 'android-checkbox-outline',
        name: 'plateformservice_check',
        title: '服务申领审核',
        permission: 1130,
        operations: ["15"],
        component: resolve => { require(['../views/plateformservice/plateformservice_check.vue'], resolve); }
    },
    browser_update: {
        path: 'browser_update',
        icon: '',
        name: 'browser_update',
        title: '浏览器上传',
        permission: 1131,
        operations: ["43"],
        component: resolve => { require(['../views/dictionary/browser_update.vue'], resolve); }
    },
    listedCompany: {
        path: 'listedCompany',
        icon: 'ios-paper-outline',
        name: 'listedCompany',
        title: '上市企业信息',
        permission: 1133,
        operations: ["11","12","13","15"],
        component: resolve => { require(['../views/plateformservice/listedCompany.vue'], resolve); }
    },
    all_plateformservice: {
        path: 'all_plateformservice',
        icon: 'ios-paper-outline',
        name: 'all_plateformservice',
        title: '全部平台服务申请',
        permission: 1134,
        operations: [],
        component: resolve => { require(['../views/plateformservice/all_plateformservice.vue'], resolve); }
    },
    usual_service: {
        path: 'usual_service',
        icon: 'ios-paper-outline',
        name: 'usual_service',
        title: '专项服务类别',
        permission: 1135,
        operations: ["11","12","13","14","15"],
        component: resolve => { require(['../views/dictionary/usual_service.vue'], resolve); }
    },
    statistics: {
        path: 'statistics',
        icon: 'ios-paper-outline',
        name: 'statistics',
        title: '数据分析',
        permission: 1136,
        operations: [],
        component: resolve => { require(['../views/statistics/statistics.vue'], resolve); }
    },
};

// 默认路由结构
export const template_default = [
    {
        icon: "ios-folder", title: "权限管理", children: [
            { icon: "person-add", name: "admin_role", title: "管理员角色" },
            { icon: "person-add", name: "admin_user_add", title: "添加管理员" },
            { icon: "person-add", name: "member_manage", title: "会员管理" },
            { icon: "gear-b", name: "update_password", title: "重置密码" }
        ]
    },
    {
        icon: 'ios-folder',
        title: '网站信息管理',
        children: [
            {
                icon: 'ios-paper-outline',
                name: 'info_list',
                title: '文章管理'
            },
            {
                icon: 'ios-paper-outline',
                name: 'index_logo',
                title: '网站图片',
            },
            {
                icon: 'ios-paper-outline',
                name: 'usual_service',
                title: '专项服务类别'
            },
            {
                icon: 'ios-paper-outline',
                name: 'system_introduction',
                title: '系统介绍'
            },
            {
                icon: 'ios-paper-outline',
                name: 'help_list',
                title: '帮助中心'
            },
            
        ]
    },
    {
        icon: 'checkmark',
        title: '信息审核',
        children: [
            {
                icon: 'toggle-filled',
                name: 'open_check',
                title: '审核开关'
            },
            {
                icon: 'android-checkbox-outline',
                name: 'firm_check',
                title: '企业注册信息审核'
            },
            {
                icon: 'android-checkbox-outline',
                name: 'service_register_check',
                title: '服务机构注册信息审核'
            },
            {
                icon: 'android-checkbox-outline',
                name: 'service_check',
                title: '服务信息审核'
            },
            {
                icon: 'android-checkbox-outline',
                name: 'demand_check',
                title: '需求信息审核'
            },           
            {
                icon: 'android-checkbox-outline',
                name: 'abutment_history',
                title: '已审核对接信息'
            },
            {
                icon: 'android-checkbox-outline',
                name: 'service_history',
                title: '已审核服务信息'
            },
            {
                icon: 'android-checkbox-outline',
                name: 'demand_history',
                title: '已审核需求信息'
            }
        ]
    },
    {
        icon: 'ios-folder',
        title: '系统设置',
        children: [
            {
                icon: 'ios-paper-outline',
                name: 'maintain',
                title: '系统开关'
            },
            { 
                icon: "gear-b",
                name: "page_manage",
                title: "模块设置" 
            },
            {
                icon: 'ios-paper-outline',
                name: 'dictionary_manage',
                title: '字典'
            },
            {
                icon: 'ios-paper-outline',
                name: 'browser_update',
                title: '浏览器上传'
            },
            {
                icon: 'ios-paper-outline',
                name: 'system_value',
                title: '系统信息设置'
            },
            {
                icon: 'ios-paper-outline',
                name: 'email_value',
                title: '邮箱接口设置'
            },
            {
                icon: 'ios-paper-outline',
                name: 'message_value',
                title: '短信接口设置'
            },
            {
                icon: 'ios-paper-outline',
                name: 'email_template',
                title: '邮件模板'
            },
            {
                icon: 'ios-paper-outline',
                name: 'message_template',
                title: '短信模板'
            }
        ]
    },
    {
        icon: 'ios-folder',
        title: '系统日志',
        children: [
            {
                icon: 'ios-paper-outline',
                name: 'admin_log',
                title: '管理员日志'
            },
            {
                icon: 'ios-paper-outline',
                name: 'user_log',
                title: '普通用户日志'
            },
            {
                icon: 'ios-paper-outline',
                name: 'feedback_manage',
                title: '问题反馈'
            },
            {
                icon: 'ios-paper-outline',
                name: 'message_manage',
                title: '消息管理'
            }
        ]
    },
    {
        icon: 'stats-bars',
        title: '数据维护',
        children: [
            {
                icon: 'archive',
                name: 'backup_database',
                title: '备份数据库'
            },
            {
                icon: 'android-exit',
                name: 'restore_database',
                title: '还原数据库'
            },
            {
                icon: 'close',
                name: 'delete_database',
                title: '删除备份数据库'
            },
            {
                icon: 'arrow-down-a',
                name: 'download_database',
                title: '下载备份数据库'
            }
        ]
    },
    {
        icon: 'ios-folder',
        title: '平台服务',
        children: [
            {
                icon: 'ios-paper-outline',
                name: 'all_plateformservice',
                title: '全部平台服务申请'
            },
            {
                icon: 'ios-paper-outline',
                name: 'release_plateformservice',
                title: '发布平台服务'
            },
            {
                icon: 'android-checkbox-outline',
                name: 'plateformservice_check',
                title: '服务申领审核'
            },
            {
                icon: 'ios-paper-outline',
                name: 'listedCompany',
                title: '上市企业信息'
            },
            
        ]
    }
];

export const renderTemplate = function(template) {
    var root = [];
    template.forEach( (item, index) => {
        var temp = { 
            name: "group"+index,
            path: "/",
            icon: 'ios-folder',
            component: Main,
            children: []
        };
        temp.icon = item.icon;
        temp.title = item.title;
        item.children.forEach(child => {
            var route = route_list[child.name];
            temp.children.push({
                icon: child.icon,
                title: child.title,
                path: route.path,
                name: route.name,
                meta: {
                    permission: route.permission,
                    operations: route.operations || []
                },
                permission: route.permission,
                operations: route.operations || [],
                component: route.component
            });
        });
        root.push(temp);
    });
    return root;
}

// 所有上面定义的路由都要写在下面的routes里
export const baseRoutes = [
    loginroute,
    otherroute,
    ...commonroutes
];
